﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace VAdvantage.Controls
{
    public partial class ImageText : UserControl
    {
        public ImageText()
        {
            InitializeComponent();
        }

        #region ICON
        public ImageSource Icon
        {
            get { return (ImageSource)GetValue(IconProperty); }
            set { SetValue(IconProperty, value); }
        }

        private const string IconPropertyName = "Icon";

        public static readonly DependencyProperty IconProperty = DependencyProperty.Register(IconPropertyName,
           typeof(ImageSource), typeof(ImageText), new PropertyMetadata(null, new PropertyChangedCallback(OnIconPropertyChanged)));

        private static void OnIconPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ((ImageText)d).OnIconPropertyChanged(e.NewValue as ImageSource);
        }

        private ImageSource _imgSource = null;
        private void OnIconPropertyChanged(ImageSource newValue)
        {
            if (img != null && newValue != null)
            {
                img.Source = newValue;
                _imgSource = null;
            }
            else
            {
                _imgSource = newValue;
            }
        }



        //public ImageSource BackgroundImage
        //{
        //    get { return (ImageSource)GetValue(IconProperty); }
        //    set { SetValue(IconProperty, value); }
        //}

        //private const string BackgroundImagePropertyName = "BackgroundImage";

        //public static readonly DependencyProperty BackgroundImageProperty = DependencyProperty.Register(BackgroundImagePropertyName,
        //   typeof(ImageSource), typeof(ToolBarButton), new PropertyMetadata(null, new PropertyChangedCallback(OnBackgroundImagePropertyChanged)));

        //private static void OnBackgroundImagePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        //{
        //    ((ToolBarButton)d).OnBackgroundImagePropertyChanged(e.NewValue as ImageSource);
        //}

        //private ImageSource _imgBSource = null;
        //private void OnBackgroundImagePropertyChanged(ImageSource newValue)
        //{
        //    if (ToolItemBrush != null && newValue != null)
        //    {
        //        backgroundImageBrush.ImageSource = newValue;
        //        _imgBSource = null;
        //    }
        //    else
        //    {
        //        _imgBSource = newValue;
        //    }
        //}


        #endregion

        #region

        public String Text
        {
            get { return (String)GetValue(TextProperty); }
            set { SetValue(TextProperty, value); }
        }

        private const string TextPropertyName = "Text";

        public static readonly DependencyProperty TextProperty = DependencyProperty.Register(TextPropertyName,
           typeof(String), typeof(ImageText), new PropertyMetadata(null, new PropertyChangedCallback(OnTextPropertyChanged)));

        private static void OnTextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ((ImageText)d).OnTextPropertyChanged(e.NewValue as String);
        }

        private String _text = null;
        private string _toolTipText;
        private void OnTextPropertyChanged(String newValue)
        {
            if (txt != null && newValue != null)
            {
                txt.Text = newValue;
                _text = null;
            }
            else
            {
                _text = newValue;
            }
        }


        #endregion

        public string ToolTipText
        {
            get
            {
                return _toolTipText;

            }

            set
            {
                _toolTipText = value;
                if (_toolTipText == null || _toolTipText.Length > 0)
                {
                    ToolTipService.SetToolTip(this, _toolTipText);
                }
            }
        }

        public new bool IsEnabled
        {
            get
            {
                return base.IsEnabled;
            }
            set
            {
                base.IsEnabled = value;
                if (value)
                {
                    txt.Opacity = 1;
                    img.Opacity = 1;
                }
                else
                {
                    txt.Opacity = .7;
                    img.Opacity = .8;
                }
            }
        }
    }
}
